package com.graduationproject.examonline.teacher.controller;

import com.graduationproject.examonline.teacher.service.TeacherService;
import com.graduationproject.examonline.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("api/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @GetMapping("/login")
    public Result login(String teacher_id, String teacher_password) {
        Result result = teacherService.login(teacher_id, teacher_password);
        return result;
    }

    /**
     * @param params JSON包含token, teacher_id, next_teacher_id, next_teacher_password
     */
    @PostMapping("/updatePassword")
    public Result updatePassword(@RequestBody Map<String, Object> params) {
        Result result = teacherService.updatePassword(params);
        return result;
    }

    @PostMapping("/updateName")
    public Result updateName(@RequestBody Map<String, Object> params) {
        return teacherService.updateName(params);
    }

    @GetMapping("/getUserInfo")
    public Result getUserInfo(String teach_id) {
        return teacherService.getUserInfo(teach_id);
    }

    @GetMapping("/getAllUserInfo")
    public Result getAllUserInfo() {
        return teacherService.getAllUserInfo();
    }

    @PostMapping("/insertTeacher")
    public Result insertTeacher(@RequestBody Map<String, Object> p) {
        return teacherService.insertTeacher(p);
    }

    @PostMapping("/updateById")
    public Result updateById(@RequestBody Map<String, Object> p) {
        return teacherService.updateById(p);
    }

}
